﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace AudioCore.Common
{
    public static class AppConfigUtils
    {
        public static bool GetString(string appConfigKey, ref string resultValue)
        {
            if (string.IsNullOrEmpty(appConfigKey))
            {
                return false;
            }
            resultValue = ConfigurationManager.AppSettings[appConfigKey];
            return true;
        }

        public static bool GetInt(string appConfigKey, ref int resultValue)
        {
            if (string.IsNullOrEmpty(appConfigKey))
            {
                return false;
            }
            string strValue = ConfigurationManager.AppSettings[appConfigKey].ToString();
            int value = 0;
            if (int.TryParse(strValue.Trim(), out value))
            {
                resultValue = value;
                return true;
            }
            else
            {
                return false;
            }
        }
        public static bool GetLastConnectionString(ref string resultValue)
        {
            if (ConfigurationManager.ConnectionStrings.Count == 0)
                return false;
            else
                resultValue = ConfigurationManager.ConnectionStrings[ConfigurationManager.ConnectionStrings.Count - 1].ConnectionString;
            return true;
        }

        public static bool GetConnectionString(string name, ref string resultValue)
        {
            if (ConfigurationManager.ConnectionStrings.Count == 0)
                return false;
            else
                resultValue = ConfigurationManager.ConnectionStrings[name].ConnectionString;
            return true;
        }
    }
}
